mirror of https://github.com/wg-easy/wg-easy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1013 B
43 lines
1013 B
export default definePermissionEventHandler(
|
|
'me',
|
|
'update',
|
|
async ({ event, user, checkPermissions }) => {
|
|
checkPermissions(user);
|
|
|
|
const { config, provider, providerConfig } = await buildOauthConfig(event);
|
|
|
|
const session = await useWGSession(event);
|
|
if (
|
|
!session.data.oauth_nonce ||
|
|
!session.data.oauth_verifier ||
|
|
!session.data.oauth_state
|
|
) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: 'Missing OAuth State',
|
|
});
|
|
}
|
|
|
|
const userInfo = await getUserInfo(
|
|
event,
|
|
config,
|
|
{
|
|
oauth_nonce: session.data.oauth_nonce,
|
|
oauth_verifier: session.data.oauth_verifier,
|
|
oauth_state: session.data.oauth_state,
|
|
},
|
|
providerConfig
|
|
);
|
|
|
|
if (!userInfo.sub) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: 'No sub set',
|
|
});
|
|
}
|
|
|
|
await Database.users.linkOauth(user.id, provider, userInfo.sub);
|
|
|
|
return sendRedirect(event, '/me');
|
|
}
|
|
);
|
|
|